package mall.pojo;

// default package
// Generated 23-Oct-2013 06:36:14 by Hibernate Tools 3.4.0.CR1

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * Orders generated by hbm2java
 */
@Entity
@Table(name = "orders")
public class Orders implements java.io.Serializable {

	private Integer id;
	private Member member;
	private Shop shop;
	private String address;
	private Date date;
	private String email;
	private String fullname;
	private String note;
	private String phone;
	private int state;
	private int paymentmethod; // 0 :cash , 1: online payment(not finished yet) ,2:online payment (finished) 
	private String stringDate;

	private Set<Orderdetail> orderdetails = new HashSet<Orderdetail>(0);

	public Orders() {
		
	}

	public Orders(Member member, Shop shop, String address, Date date,
			String email, String fullname, String note, String phone, int state,int paymentMethod) {
		this.member = member;
		this.shop = shop;
		this.address = address;
		this.date = date;
		this.email = email;
		this.fullname = fullname;
		this.note = note;
		this.phone = phone;
		this.state = state;
		this.paymentmethod=paymentMethod;
	}

	public Orders(Member member, Shop shop, String address, Date date,
			String email, String fullname, String note, String phone,
			byte state,int paymentMethod, Set<Orderdetail> orderdetails) {
		this.member = member;
		this.shop = shop;
		this.address = address;
		this.date = date;
		this.email = email;
		this.fullname = fullname;
		this.note = note;
		this.phone = phone;
		this.state = state;
		this.paymentmethod=paymentMethod;
		this.orderdetails = orderdetails;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "member_id", nullable = false)
	public Member getMember() {
		return this.member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "shop_id", nullable = false)
	public Shop getShop() {
		return this.shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	@Column(name = "address", nullable = false)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", nullable = false, length = 19)
	public Date getDate() {
		SimpleDateFormat sdf = new java.text.SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		this.stringDate=sdf.format(this.date);
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	@Column(name = "email", nullable = false, length = 45)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "fullname", nullable = false, length = 45)
	public String getFullname() {
		return this.fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	@Column(name = "note", nullable = false)
	public String getNote() {
		return this.note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Column(name = "phone", nullable = false, length = 45)
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "state", nullable = false)
	public int getState() {
		return this.state;
	}

	public void setState(int state) {
		this.state = state;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "orders")
	public Set<Orderdetail> getOrderdetails() {
		return this.orderdetails;
	}

	public void setOrderdetails(Set<Orderdetail> orderdetails) {
		this.orderdetails = orderdetails;
	}
	
	@Transient
	public String getStringDate() {
		return stringDate;
	}
	
	public void setStringDate(String stringDate) {
		this.stringDate = stringDate;
	}
	@Column(name = "payment_method", nullable = false)
	public int getPaymentmethod() {
		return paymentmethod;
	}

	public void setPaymentmethod(int paymentMethod) {
		this.paymentmethod = paymentMethod;
	}
	
}
